home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stut_src / arbopars.c < prev    next >
Text File  |  1996-05-26  |  9KB  |  428 lines

  1. /*
  2.  * arbopars.c
  3.  *
  4.  * Purpose:
  5.  * --------
  6.  * Fonctions permettant la manipulation
  7.  * des paramŠtres d'une pge arbo
  8.  *
  9.  * History:
  10.  * --------
  11.  * 04.12.94: Created by flanque
  12.  */
  13.  
  14.     #include "!OPTIONS.H"                /* Options de compilation */         
  15.     #define    THIS_FILE    "ARBOPARS.C v1.00 - 03.95"
  16.           
  17. /*
  18.  * System headers:
  19.  */
  20.     #include    <stdio.h>
  21.     #include <stdlib.h>
  22.     #include    <string.h>
  23.     
  24. /*
  25.  * Custom headers:
  26.  */
  27.     #include    "ARB_OUT.H"
  28.  
  29.     #include "SPEC_PU.H"                    /* Listes... */    
  30.     #include "S_MALLOC.H"
  31.     #include    "MAIN_PU.H"    
  32.     #include    "DEBUG_PU.H"    
  33.     #include    "FILES_PU.H"    
  34.     #include    "LISTS_PU.H"    
  35.     #include    "DEF_ARBO.H"
  36.     #include    "AFILE_PU.H"
  37.     #include    "ARPAR_PU.H"                /* this */
  38.     #include "WIN_PU.H"
  39.  
  40.  
  41. /*
  42.  * ------------------------ FUNCTIONS -------------------------
  43.  */
  44.  
  45.  
  46. /*
  47.  * Duplicate_TextParList(-)
  48.  *
  49.  * Purpose:
  50.  * --------
  51.  * Duplique une liste chain‚ee de ARBO_TEXTPAR
  52.  *
  53.  * Suggest:
  54.  * ------
  55.  * Move me to another file
  56.  *
  57.  * History:
  58.  * --------
  59.  * 04.12.94: fplanque: Created / replaces old duplicate_textpar() / 
  60.  *           this one uses dup_String() instead of strcpy() which is supposed was a bug!
  61.  * 14.05.95: retourne un ARBO_TEXTPAR * au lieu de VOID ce qui semblait stupide et dangereux
  62.  */
  63. ARBO_TEXTPAR *    Duplicate_TextParList( 
  64.                 const ARBO_TEXTPAR *    pTextPar_FirstSrce )    /* In: Ptr sur 1er elt liste source */
  65. {
  66.     const ARBO_TEXTPAR *        pTextPar_Srce = pTextPar_FirstSrce;    /* 1er elt de la liste destination */
  67.     ARBO_TEXTPAR *        pTextPar_FirstDest;            /* 1er elt de la liste destination */
  68.     ARBO_TEXTPAR * *    lastptr_to_next = &pTextPar_FirstDest;    /* Adr du dernier ptr sur le champ suivant */
  69.     ARBO_TEXTPAR *        pTextPar_Dest;                    /* Elt courant de la liste destination */
  70.  
  71.     /*
  72.      * Copie tous les ‚l‚ments: 
  73.      */
  74.     while( pTextPar_Srce != NULL )
  75.     {
  76.         /*
  77.          * Cr‚e nouvel ‚l‚ment; 
  78.          */
  79.         pTextPar_Dest = MALLOC( sizeof( ARBO_TEXTPAR ) );
  80.  
  81.         /*
  82.          * Copie le contenu: 
  83.          */
  84.         pTextPar_Dest -> fnct_no = pTextPar_Srce -> fnct_no;
  85.         pTextPar_Dest -> nom = dup_String( pTextPar_Srce -> nom );
  86.  
  87.         /*
  88.          * Lie ce champ au pr‚c‚dent: 
  89.          */
  90.         *lastptr_to_next = pTextPar_Dest;
  91.         /*
  92.          * Nouvelle adr du dernier ptr sur champ suivant: 
  93.          */
  94.         lastptr_to_next = &(pTextPar_Dest -> next);
  95.                         
  96.         /*
  97.          * Passe au champ source suivant: 
  98.          */
  99.         pTextPar_Srce = pTextPar_Srce -> next;
  100.     }
  101.  
  102.     /*
  103.      * Signale fin de la liste: 
  104.      */
  105.     *lastptr_to_next = NULL;
  106.  
  107.     /*
  108.      * Retourne ptr sur nlle liste: 
  109.      */
  110.     return    pTextPar_FirstDest;
  111. }
  112.  
  113.  
  114.  
  115.  
  116. /*
  117.  * Delete_TextParList(-)
  118.  *
  119.  * Purpose:
  120.  * --------
  121.  * Efface 1 liste de paramŠtres textuels de la m‚moire
  122.  *
  123.  * History:
  124.  * --------
  125.  * 1993: fplanque: Created
  126.  * 24.05.94: utilisation de free_String()
  127.  * 02.12.94: change name from free_atextpar()
  128.  * 14.02.95: verified mallocs
  129.  */
  130. void    Delete_TextParList( 
  131.             ARBO_TEXTPAR *    arbo_textpar )
  132. {
  133.     ARBO_TEXTPAR    *    next_textpar;
  134.  
  135.     while( arbo_textpar != NULL )
  136.     {
  137.         next_textpar = arbo_textpar -> next;    /* ParamŠtre suivant */
  138.  
  139.         free_String( arbo_textpar -> nom );        /* Efface le nom */
  140.         FREE( arbo_textpar );                        /* Efface le paramŠtre */
  141.  
  142.         arbo_textpar = next_textpar;                /* Passe au param suivant */
  143.     }
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. /*
  152.  * Get_ithTextParInList(-)
  153.  *
  154.  * Purpose:
  155.  * --------
  156.  * Trouve les parametres de son num‚ro d'ordre ds la liste
  157.  *
  158.  * History:
  159.  * --------
  160.  * 04.12.94: fplanque: Created
  161.  */
  162. ARBO_TEXTPAR    *    Get_ithTextParInList( 
  163.                             ARBO_TEXTPAR *    pTextPar, 
  164.                             int                 n_Index )
  165. {
  166.     int    i;        /* Compteur */
  167.  
  168.     for( i=0; i < n_Index  &&  pTextPar != NULL; i++ )
  169.     {    /*
  170.          * Tant qu'on est pas arriv‚ au champ qui nous int‚resse
  171.          * et qu'on est pas … la fin de la liste: 
  172.          * Passe au champ suivant 
  173.          */
  174.         pTextPar = pTextPar -> next;
  175.     }
  176.  
  177.     return    pTextPar;        /* Ptr sur params; NULL si pas trouv‚ */
  178. }
  179.    
  180.  
  181.  
  182. /*
  183.  * InputField_Save(-)
  184.  *
  185.  * Purpose:
  186.  * --------
  187.  * Sauve paramŠtres d'un champ de saisie
  188.  *
  189.  * History:
  190.  * --------
  191.  * 17.12.94: fplanque: Created
  192.  */
  193. void    InputField_Save( 
  194.             INPUT_FPAR    *    pInputFPar,     /* In: Champ … sauver */
  195.             FILE             *    fstream )        /* In: Fichier vers lequel sauver */
  196. {
  197.     /*
  198.      * Sauve tout sauf chaine:
  199.      */
  200.     fwrite( pInputFPar, 1, sizeof( INPUT_FPAR ) - sizeof( char * ) , fstream );
  201.  
  202.     /*
  203.      * Sauve chaine du contenu par d‚faut:
  204.      */
  205.      save_String( pInputFPar -> psz_DefText, fstream );
  206. }
  207.  
  208.  
  209. /*
  210.  * InputField_Load(-)
  211.  *
  212.  * Purpose:
  213.  * --------
  214.  * Charge paramŠtres d'un champs de saisie
  215.  *
  216.  * History:
  217.  * --------
  218.  * 17.12.94: fplanque: Created
  219.  * 23.01.95: ajout FieldCode
  220.  */
  221. void    InputField_Load( 
  222.             INPUT_FPAR    *    pInputFPar, /* In: Champ ds lequel on charge */
  223.             FILE             *    fstream,        /* In: Fichier duquel on charge */
  224.             int                n_Version )    /* In: version du fichier */
  225. {
  226.     /*
  227.      * Charge tout sauf chaine:
  228.      */
  229.     if( n_Version == 0x0002 )
  230.     {
  231.         fread( pInputFPar, 1, 28, fstream );
  232.  
  233.         memcpy( &(pInputFPar -> InFieldFlags), ((char *)pInputFPar) + 2, 26 );
  234.  
  235.         pInputFPar -> ul_CodeChamp = get_InFieldCode( pInputFPar -> fnct_no );
  236.     }
  237.     else
  238.     {
  239.         fread( pInputFPar, 1,  sizeof( INPUT_FPAR ) - sizeof( char * ), fstream );
  240.     }
  241.  
  242.     /*
  243.      * Charge chaine du contenu par d‚faut:
  244.      */
  245.      pInputFPar -> psz_DefText = load_String( fstream );
  246. }
  247.  
  248.  
  249.  
  250. /*
  251.  * AListPars_Save(-)
  252.  *
  253.  * Purpose:
  254.  * --------
  255.  * Sauve paramŠtres de liste (d'affichage)
  256.  *
  257.  * History:
  258.  * --------
  259.  * 26.01.95: fplanque: Created
  260.  */
  261. void    AListPars_Save(
  262.             ARBO_LISTPARS    *    pAListPars, /* In: ParamŠtres … sauver */
  263.             FILE                 *    fstream )    /* In: Fichier vers lequel sauver */
  264. {
  265.     if( pAListPars == NULL )
  266.     {
  267.         fputc( 'l', fstream );
  268.     }
  269.     else
  270.     {
  271.         fputc( 'L', fstream );
  272.         fwrite( pAListPars, 1, sizeof( ARBO_LISTPARS ), fstream );
  273.     }
  274. }
  275.  
  276.  
  277.  
  278. /*
  279.  * AListPars_Load(-)
  280.  *
  281.  * Purpose:
  282.  * --------
  283.  * Charge paramŠtres de liste (d'affichage)
  284.  *
  285.  * History:
  286.  * --------
  287.  * 26.01.95: fplanque: Created
  288.  */
  289. ARBO_LISTPARS    *    AListPars_Load(        /* Out: paramŠtres charg‚s */
  290.             FILE                 *    fstream )    /* In:  Fichier depuis lequel on charge */
  291. {
  292.     if( fgetc( fstream ) == 'L' )
  293.     {
  294.          ARBO_LISTPARS    * pAListPars = MALLOC( sizeof( ARBO_LISTPARS ) );
  295.         fread( pAListPars, 1, sizeof( ARBO_LISTPARS ), fstream );
  296.         
  297.         return    pAListPars;
  298.     }
  299.     
  300.     return    NULL;
  301. }
  302.  
  303.  
  304.  
  305. /*
  306.  * OutputField_Save(-)
  307.  *
  308.  * Purpose:
  309.  * --------
  310.  * Sauve paramŠtres des champs de sorttie (affichage)
  311.  *
  312.  * History:
  313.  * --------
  314.  * 17.12.94: fplanque: Created
  315.  */
  316. void    OutputField_Save( 
  317.             OUTPUT_FPAR    *    pOutputFPar,     /* In: Champ … sauver */
  318.             FILE             *    fstream )        /* In: Fichier vers lequel sauver */
  319. {
  320.     /*
  321.      * Sauve tout:
  322.      */
  323.     fwrite( pOutputFPar, 1, sizeof( OUTPUT_FPAR ), fstream );
  324. }
  325.  
  326.  
  327.  
  328. /*
  329.  * OutputField_Load(-)
  330.  *
  331.  * Purpose:
  332.  * --------
  333.  * Charge paramŠtres d'un champs de sortie
  334.  *
  335.  * History:
  336.  * --------
  337.  * 17.12.94: fplanque: Created
  338.  * 23.01.95: gesion codechamp
  339.  */
  340. void    OutputField_Load( 
  341.             OUTPUT_FPAR    *    pOutputFPar, /* In: Champ ds lequel on charge */
  342.             FILE             *    fstream,        /* In: Fichier duquel on charge */
  343.             int                n_Version )    /* In: version du fichier */
  344. {
  345.     /*
  346.      * Charge tout:
  347.      */
  348.     if( n_Version == 0x0002 )
  349.     {
  350.         fread( pOutputFPar, 1, 20, fstream );
  351.     
  352.         memcpy( &(pOutputFPar -> OutFieldFlags), ((char*)pOutputFPar) +2, 18 );
  353.  
  354.         pOutputFPar -> ul_CodeChamp = get_OutFieldCode( pOutputFPar -> fnct_no );
  355.  
  356.         switch( pOutputFPar -> fnct_no )
  357.         {
  358.             case    0010:
  359.                 pOutputFPar -> fnct_no = FO_COMMENT;
  360.                 pOutputFPar -> OutFieldFlags.u_GroupId = 1;
  361.                 break;
  362.         
  363.             case    0100:
  364.                 pOutputFPar -> fnct_no = FO_RECNUMBER;
  365.                 pOutputFPar -> OutFieldFlags.u_GroupId = 2;
  366.                 break;
  367.         
  368.             case    0200:
  369.                 pOutputFPar -> fnct_no = FO_CREATEDATE;
  370.                 pOutputFPar -> OutFieldFlags.u_GroupId = 2;
  371.                 break;
  372.         
  373.             case    0220:
  374.                 pOutputFPar -> fnct_no = FO_PUBPRIV;
  375.                 pOutputFPar -> OutFieldFlags.u_GroupId = 2;
  376.                 break;
  377.         
  378.             case    0110:
  379.                 pOutputFPar -> fnct_no = FO_PAGENUMBER;
  380.             case    FO_TEXT:
  381.                 pOutputFPar -> OutFieldFlags.u_GroupId = 4;
  382.                 break;
  383.         
  384.             default:
  385.                 pOutputFPar -> OutFieldFlags.u_GroupId = 2;
  386.         }
  387.     }
  388.     else
  389.     {
  390.         fread( pOutputFPar, 1, sizeof( OUTPUT_FPAR ), fstream );
  391.     }
  392. }
  393.  
  394.  
  395.  
  396. /*
  397.  * TextParList_Replace1Content(-)
  398.  *
  399.  * History:
  400.  * --------
  401.  * 17.12.94: fplanque: created
  402.  * 11.07.95: fplanque: N'EST PLUS UTILISE! (etait utilise par DataPage_AutoParam())
  403.  */
  404. BOOL    TextParList_Replace1Content(                    /* Out: TRUE_1 si ok */
  405.                 ARBO_TEXTPAR *    pTextPar_List,            /* In: Liste des textpars … remplacer */
  406.                 int                n_Fnct,                    /* In: Fonction du textpar … remplacer */
  407.                 const char     * cpsz_NewContent )        /* In: ModŠle du nouveau contenu */
  408. {
  409.     ARBO_TEXTPAR *    pTextPar_Found;
  410.     
  411.     /*
  412.      * Cherche par de fonction demand‚e:
  413.      */
  414.     pTextPar_Found = Lookup_SingleLinkList( pTextPar_List, n_Fnct );
  415.     if( pTextPar_Found == NULL )
  416.     {
  417.         return    FALSE0;
  418.     }
  419.  
  420.     /*
  421.      * Trouv‚, remplace le nom:
  422.      */
  423.     free_String( pTextPar_Found -> nom );
  424.     pTextPar_Found -> nom = STRDUP( cpsz_NewContent );
  425.     
  426.     return     TRUE_1;
  427. }            
  428.